<template>
  <el-dialog title="审核评论" :visible.sync="visible" v-if="visible">
    <el-form ref="formData" :model="formData" label-position="right" label-width="80px">
      <el-form-item label="文章标题">
        <el-input v-model="formData.article.title" disabled/>
      </el-form-item>
      <el-form-item label="评论人">
        <el-input v-model="formData.name" disabled/>
      </el-form-item>
      <el-form-item label="评论内容">
        <el-input type="textarea" maxlength="200" disabled show-word-limit v-model="formData.content"/>
      </el-form-item>
      <el-form-item label="评论状态">
        <el-select v-model="formData.commentStatus" disabled>
          <el-option :value="1" label="待审"/>
          <el-option :value="2" label="通过"/>
          <el-option :value="3" label="拒绝"/>
        </el-select>
      </el-form-item>
      <el-form-item label="数据状态">
        <el-radio-group v-model="formData.status" disabled>
          <el-radio :label="1">可用</el-radio>
          <el-radio :label="2">禁用</el-radio>
        </el-radio-group>
        <span v-if="formData.status === 2" style="margin-left: 10px;color: red;">被禁用数据无法审核！</span>
      </el-form-item>
      <el-form-item>
        <template v-if="formData.status === 1">
          <el-button type="success" v-if="formData.commentStatus !== 2" @click="exam(2)">通过</el-button>
          <el-button type="danger" v-if="formData.commentStatus !== 3" @click="exam(3)">拒绝</el-button>
        </template>
        <el-button type="warning" @click="visible = false">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
const formData = {
  commentId: '',
  name: '',
  content: '',
  commentStatus: 1,
  article: {
    title: ''
  }
}
export default {
  name: 'CommentExam',
  data () {
    return {
      visible: false,
      formData: { ...formData }
    }
  },
  methods: {
    init (commentId) {
      this.visible = true
      this.$http.get(`/admin/comment/info/${commentId}`).then(data => {
        this.formData = { ...data.data }
      })
    },
    exam (commentStatus) {
      this.$refs.formData.validate(valid => {
        if (valid) {
          this.$http.post('admin/comment/exam', { commentId: this.formData.commentId, commentStatus }).then(() => {
            this.$alert('审核完成', { type: 'success' }).then(() => {
              this.visible = false
              this.$emit('onCloseDialog')
            })
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
